package com.sunfeng.n6;

import lombok.extern.slf4j.Slf4j;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 测试延时
 *
 * @author sunfeng
 * @date 2021/03/03 13:53
 **/
@Slf4j(topic = "c.TestTimer")
public class TestTimer2 {
    public static void main(String[] args) {

        ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);



        pool.schedule(()->{
            log.debug("Task1");
            int i=1/0;
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },1, TimeUnit.SECONDS);

        pool.schedule(()->{
            log.debug("Task2");
        },1, TimeUnit.SECONDS);

        pool.shutdown();
    }
}
